package chen.web.back.client.post;

import chen.web.back.client.Entry;
import chen.web.back.client.EntrySelectionListener;
import chen.web.back.client.Workbench;

import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.ListView;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.History;

public class PostNavigation extends ContentPanel implements ValueChangeHandler<String> {
	
	private Entry subjectChecking = new Entry("审核新主题", "subject-checking");
	private Entry replyChecking = new Entry("审核新回复", "subject-checking");
	private Entry subjectRecycleBin = new Entry("主题回收站", "subject-recycle-bin");
	private Entry replyRecycleBin = new Entry("回复回收站", "reply-recycle-bin");
	public PostNavigation() {
		this.setHeading("帖子管理");
		this.getHeader().setStyleAttribute("font-size", "13px");
		this.setBodyBorder(false);

		ListView<Entry> list = new ListView<Entry>();
		ListStore<Entry> store = new ListStore<Entry>();
		store.add(subjectChecking);
		store.add(replyChecking);
		store.add(subjectRecycleBin);
		store.add(replyRecycleBin);
		
		list.setStore(store);
		list.setDisplayProperty("name");
		list.setBorders(false);
		list.setStyleAttribute("color", "#416AA3");
		list.setStyleAttribute("text-indent", "1em");
		list.getSelectionModel().addSelectionChangedListener(new EntrySelectionListener());
		
		this.add(list);
		History.addValueChangeHandler(this);
		History.fireCurrentHistoryState();
	}

	@Override
	public void onValueChange(ValueChangeEvent<String> event) {
		// TODO Auto-generated method stub
		String url = event.getValue();
		if(subjectChecking.getURL().equals(url)){
			SubjectCheckingPanel panel = new SubjectCheckingPanel();
			TabItem tab = Workbench.getInstance().generalTabItem(subjectChecking);
			tab.add(panel);
			Workbench.getInstance().addTabItem(tab);
		} else if(replyChecking.getURL().equals(url)){
			
		} else if(subjectRecycleBin.getURL().equals(url)){
			SubjectRecycleBinPanel panel = new SubjectRecycleBinPanel();
			TabItem tab = Workbench.getInstance().generalTabItem(subjectRecycleBin);
			tab.add(panel);
			Workbench.getInstance().addTabItem(tab);
		} else if(replyRecycleBin.getURL().equals(url)){
			ReplyRecycleBinPanel panel = new ReplyRecycleBinPanel();
			TabItem tab = Workbench.getInstance().generalTabItem(replyRecycleBin);
			tab.add(panel);
			Workbench.getInstance().addTabItem(tab);
		}
	}

/*	
	private List<ModelData> getData(){
		List<ModelData> list = new ArrayList<ModelData>();
		for(int i=0; i<3; i++){
			ModelData data = new BaseModelData();
			list.add(data);
		}
		list.get(0).set("name", "系统配置");
		list.get(1).set("name", "邮箱配置");
		list.get(2).set("name", "系统配置");
		return list;
	}*/

}
